﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using RescueApp.Models;

namespace RescueApp.Data
{
    //用Fluent API 来配置 RescueApply 实体类的数据库映射和约束
    public class RescueApplyConfig : IEntityTypeConfiguration<RescueApply>
    {
        public void Configure(EntityTypeBuilder<RescueApply> rescueApply)
        {
            rescueApply.ToTable("RescueApply");

            // 配置 RescueApply 类的属性
            rescueApply.HasKey(p => p.RescueID); // 主键是 RescueID
            rescueApply.Property(p => p.RescueID).ValueGeneratedNever(); // RescueID 由外部生成。

            rescueApply.Property(p => p.LicenseID).IsRequired().HasMaxLength(10);
            rescueApply.Property(p => p.CarType).IsRequired().HasMaxLength(20);
            rescueApply.Property(p => p.DriverLicenseID).IsRequired().HasMaxLength(18);
            rescueApply.Property(p => p.Phone).IsRequired().HasMaxLength(11);
            rescueApply.Property(p => p.RescueLocation).IsRequired().HasMaxLength(50);
            rescueApply.Property(p => p.Destination).IsRequired().HasMaxLength(50);
            rescueApply.Property(p => p.FillingDate).IsRequired();
        }
    }
}